//
//  CustomCellTableViewController.swift
//  MacStudy
//
//  Created by 30san on 2020/9/24.
//  Copyright © 2020 Dawninest. All rights reserved.
//

import Cocoa

class XibCustomCellTableViewController: NSViewController {

    @IBOutlet weak var tableView: NSTableView!
    
    private let cellIdentifier = "cellIdentifier"
    
    private let dataSources = [
        ["icon", "asdf"],
        ["icon", "爱仕达多"],
        ["icon", "阿斯顿发"],
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(NSNib(nibNamed: "XibCell", bundle: nil), forIdentifier: NSUserInterfaceItemIdentifier.init(cellIdentifier))
    }
}

extension XibCustomCellTableViewController: NSTableViewDataSource {
    func numberOfRows(in tableView: NSTableView) -> Int {
        return dataSources.count
    }
}


extension XibCustomCellTableViewController: NSTableViewDelegate {
    func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
        return 100
    }
    
    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
        let cell: XibCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier.init(cellIdentifier), owner: self) as! XibCell
        cell.imageV?.image = NSImage(named: dataSources[row][0])
        cell.contentLabel.stringValue = dataSources[row][1]
        return cell
    }
}
